﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class admin_cms_default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                Load_yahoo();
            }


        }

    }
    protected void checkgroupyahoo_skype_click(object sender, EventArgs e)
    {
        if (checkgroupyahoo_skype.SelectedItem.Value.ToString() == "1" || checkgroupyahoo_skype.SelectedItem.Value.ToString() == "2")
        {
            Panel_dulich_maybay.Visible = true;
            Panel_Hotline.Visible = false;
            Panel_Yahoo_Skyper.Visible = true;
            Load_yahoo();
        }
        if (checkgroupyahoo_skype.SelectedItem.Value.ToString() == "3")
        {
            Panel_dulich_maybay.Visible = false;
            Panel_Yahoo_Skyper.Visible = false;
            Panel_Hotline.Visible = true;
            GridView1.DataSource = DataAccess.ExeSQLToDataTable("select * from Yahoo where Check_Hotline=checkgroupyahoo_skype.SelectedItem.Value");
            GridView1.DataBind();
            Load_yahoo();
        }

        Load_yahoo();
    }

    protected void Load_yahoo()
    {
        string check = string.Empty;
        if (checkgroupyahoo_skype.SelectedItem != null)
        {
            check = checkgroupyahoo_skype.SelectedItem.Value;
            switch (check)
            {
                case "1":
                    string sql = "select * from Yahoo where Check_Skype_Yahoo=1";
                    DataTable dtyahoo = DataAccess.ExeSQLToDataTable(sql);
                    if (dtyahoo.Rows.Count > 0)
                    {
                        GridView1.DataSource = dtyahoo;
                        GridView1.DataBind();
                    }
                    break;
                case "2":
                    string sql1 = "select * from Yahoo where Check_Skype_Yahoo=2";
                    DataTable dtyahoo1 = DataAccess.ExeSQLToDataTable(sql1);
                    if (dtyahoo1.Rows.Count > 0)
                    {
                        GridView1.DataSource = dtyahoo1;
                        GridView1.DataBind();
                    }
                    break;
                default:
                    string sql2 = "select * from Yahoo where Check_Hotline=3";
                    DataTable dtyahoo2 = DataAccess.ExeSQLToDataTable(sql2);
                    if (dtyahoo2.Rows.Count > 0)
                    {
                        GridView1.DataSource = dtyahoo2;
                        GridView1.DataBind();
                    }
                    break;
            }
        }

    }
    protected void bt_delete_yahoo(object sender, EventArgs e)
    {

    }

    protected void grv_yahoo_click(object sender, CommandEventArgs e)
    {

        string IdYahoo = e.CommandArgument.ToString();
        string CheckName = e.CommandName.ToString();
        if (CheckName == "X")
        {

            DataAccess.ExeNonStored("Yahoo_Delete", "@IdYahoo", IdYahoo);
            Response.Write("<script>alert('Bạn xóa thành công 1 bản ghi')</script>");
            Load_yahoo();
        }
        else
        {
            DataTable dtgrv_yahoo = new DataTable();
            dtgrv_yahoo = DataAccess.ExeStoredToDataTable("Yahoo_Load_Select", "IdYahoo", Convert.ToInt32(IdYahoo));
            if (dtgrv_yahoo.Rows.Count > 0)
            {
                txtname.Text = dtgrv_yahoo.Rows[0][1].ToString();
                txtnick.Text = dtgrv_yahoo.Rows[0][2].ToString();
                txtstatus.Text = dtgrv_yahoo.Rows[0][3].ToString();
                txtsort.Text = dtgrv_yahoo.Rows[0][4].ToString();
                txt_hotline.Text = dtgrv_yahoo.Rows[0][1].ToString();
                Session.Add("IdYahoo", IdYahoo);
            }
        }
    }
    protected void Yahoo_Insert(object sender, EventArgs e)
    {//kiem tra check yahoo skyper vong 1
        string hotroyahoo = string.Empty;
        string hotroskype = string.Empty;
        string hotline = string.Empty;
        string hotro_maybay_dulich = string.Empty;
        if (checkgroupyahoo_skype.SelectedItem != null)
        {
            if (checkgroupyahoo_skype.SelectedItem.Value == "3")
            {
                hotline = "3";
                DataAccess.ExeNonSQL("Insert into Yahoo(Name,Check_Hotline) values(N'" + txt_hotline.Text + "'," + hotline + ") ");
                Load_yahoo();
            }
            else
            {
                if (chckgroupdulich_maybay.SelectedItem != null)
                {
                    if (checkgroupyahoo_skype.SelectedItem.Value == "1")
                    {
                        hotroyahoo = "1";
                        if (chckgroupdulich_maybay.SelectedItem.Value == "1")
                        {
                            hotro_maybay_dulich = "11";
                        }
                        if (chckgroupdulich_maybay.SelectedItem.Value == "2")
                        {
                            hotro_maybay_dulich = "22";
                        }
                    }
                    if (checkgroupyahoo_skype.SelectedItem.Value == "2")
                    {
                        hotroyahoo = "2";
                        if (chckgroupdulich_maybay.SelectedItem.Value == "1")
                        {
                            hotro_maybay_dulich = "33";
                        }
                        if (chckgroupdulich_maybay.SelectedItem.Value == "2")
                        {
                            hotro_maybay_dulich = "44";
                        }
                    }
                    if (checkgroupyahoo_skype.SelectedItem.Value == "3")
                    {
                        hotline = "3";
                    }

                    string Name = txtname.Text;
                    string Nikc = txtnick.Text;
                    int? Status = null;
                    if (!string.IsNullOrEmpty(txtstatus.Text))
                    {
                        Status = Convert.ToInt32(txtstatus.Text);
                    }
                    int? Sort = null;
                    if (!string.IsNullOrEmpty(txtsort.Text))
                    {
                        Sort = Convert.ToInt32(txtsort.Text);
                    }
                    // DataAccess.ExeNonStored("Yahoo_Insert", "@Name", Name, "@Nick", Nikc, "@Status", Status, "@Sort", Sort);
                    string sql_insert_yahoo = "Insert into Yahoo(Name,Nick,status,Sort,Check_Skype_Yahoo,Check_DuLich_VeMB) values(N'" + Name + "',N'" + Nikc + "','" + Status + "','" + Sort + "','" + hotroyahoo + "','" + hotro_maybay_dulich + "') ";
                    DataAccess.ExeNonSQL(sql_insert_yahoo);
                    Response.Write("<script>alert('Bạn thêm thành công 1 bản ghi')</script>");
                    Load_yahoo();
                }
                else
                {
                    Response.Write("<script>alert('Bạn chưa chọn hỗ trợ du lịch hoặc hỗ trợ máy bay')</script>");
                }
            }
        }
        else
        {
            Response.Write("<script>alert('Bạn vui lòng chọn: Hỗ trợ Yahoo || Hỗ trợ Skype || Hotline')</script>");
        }

    }
    protected void yahoo_update(object sender, EventArgs e)
    {
        string hotroyahoo = string.Empty;
        string hotroskype = string.Empty;
        string hotline = string.Empty;
        string hotro_maybay_dulich = string.Empty;

        if (checkgroupyahoo_skype.SelectedItem != null)
        {
            if (checkgroupyahoo_skype.SelectedItem.Value == "1")
            {
                if (chckgroupdulich_maybay.SelectedItem != null)
                {
                    hotroyahoo = "1";
                    if (chckgroupdulich_maybay.SelectedItem.Value == "1")
                    {
                        hotro_maybay_dulich = "11";
                    }
                    if (chckgroupdulich_maybay.SelectedItem.Value == "2")
                    {
                        hotro_maybay_dulich = "22";
                    }

                }
                else
                {
                    Response.Write("<script>alert('Bạn chưa chọn hỗ trợ du lịch hoặc hỗ trợ máy bay')</script>");
                }
               
                int idyahoo = Convert.ToInt32(Session["IdYahoo"].ToString());
                string Name = txtname.Text;
                string Nikc = txtnick.Text;
                int? Status = null;
                if (!string.IsNullOrEmpty(txtstatus.Text))
                {
                    Status = Convert.ToInt32(txtstatus.Text);
                }

                int? Sort = null;
                if (!string.IsNullOrEmpty(txtsort.Text))
                {
                    Sort = Convert.ToInt32(txtsort.Text);
                }
                //DataAccess.ExeNonStored("Yahoo_Update", "@IdYahoo", idyahoo, "@Name", Name, "@Nick", Nikc, "@Status", Status, "@Sort", Sort);
                string sqlupdate = "update Yahoo set Name=N'" + Name + "',Nick=N'" + Nikc + "',Status='" + Status + "',Sort='" + Sort + "',Check_Skype_Yahoo='" + hotroyahoo + "',Check_DuLich_VeMB='" + hotro_maybay_dulich + "' where IdYahoo='" + idyahoo + "'";
                DataAccess.ExeNonSQL(sqlupdate);
                Response.Write("<script>alert('Bạn sửa thành công 1 bản ghi')</script>");
                Load_yahoo();
            }
            if (checkgroupyahoo_skype.SelectedItem.Value == "2")
            {
                if (chckgroupdulich_maybay.SelectedItem != null)
                {
                    hotroyahoo = "2";
                    if (chckgroupdulich_maybay.SelectedItem.Value == "1")
                    {
                        hotro_maybay_dulich = "33";
                    }
                    if (chckgroupdulich_maybay.SelectedItem.Value == "2")
                    {
                        hotro_maybay_dulich = "44";
                    }
                }
                else
                {
                    Response.Write("<script>alert('Bạn chưa chọn hỗ trợ du lịch hoặc hỗ trợ máy bay')</script>");
                }

                int idyahoo = Convert.ToInt32(Session["IdYahoo"].ToString());
                string Name = txtname.Text;
                string Nikc = txtnick.Text;
                int? Status = null;
                if (!string.IsNullOrEmpty(txtstatus.Text))
                {
                    Status = Convert.ToInt32(txtstatus.Text);
                }

                int? Sort = null;
                if (!string.IsNullOrEmpty(txtsort.Text))
                {
                    Sort = Convert.ToInt32(txtsort.Text);
                }
                //DataAccess.ExeNonStored("Yahoo_Update", "@IdYahoo", idyahoo, "@Name", Name, "@Nick", Nikc, "@Status", Status, "@Sort", Sort);
                string sqlupdate = "update Yahoo set Name=N'" + Name + "',Nick=N'" + Nikc + "',Status='" + Status + "',Sort='" + Sort + "',Check_Skype_Yahoo='" + hotroyahoo + "',Check_DuLich_VeMB='" + hotro_maybay_dulich + "' where IdYahoo='" + idyahoo + "'";
                DataAccess.ExeNonSQL(sqlupdate);
                Response.Write("<script>alert('Bạn sửa thành công 1 bản ghi')</script>");
                Load_yahoo();
            }
            if (checkgroupyahoo_skype.SelectedItem.Value == "3")
            {
                hotline = "3";
                string sqlupdate1 = "update Yahoo set Name=N'" + txt_hotline.Text + "' where IdYahoo='" + Convert.ToInt32(Session["IdYahoo"].ToString()) + "'";
                DataAccess.ExeNonSQL(sqlupdate1);
                Response.Write("<script>alert('Bạn sửa thành công 1 bản ghi')</script>");
                Load_yahoo();
            }

        }
        else
        {
            Response.Write("<script>alert('Bạn vui lòng chọn: Hỗ trợ Yahoo || Hỗ trợ Skype || Hotline')</script>");
        }

    }
}